
import {
  getCategory1ListApi,
  getCategory2ListApi,
  getCategory3ListApi,
} from "@/api/product/category";

const state = {
  category1Id: undefined,
  category2Id: undefined,
  category3Id: undefined,
  category1List: [],
  category2List: [],
  category3List: [],
};
const mutations = {
  GET_CATEGORY1LIST:(state,{data})=>{
    state.category1List = data
  },
  GET_CATEGORY2LIST:(state,{res,category1Id})=>{
    state.category2List = res.data
    state.category1Id = category1Id
    state.category3List = []
  },
  GET_CATEGORY3LIST:(state,{res,category2Id})=>{
    state.category3List = res.data
    state.category2Id = category2Id
  },
  UPDATE_CATEGORY3ID:(state,category3Id)=>{
    state.category3Id = category3Id
  },
};
const actions = {
  getCategory1List: async ({commit,state})=>{
    const res = await getCategory1ListApi()
    commit('GET_CATEGORY1LIST',res)
  },
  getCategory2List:async ({commit,state},category1Id)=>{
       const res = await getCategory2ListApi(category1Id)
      // console.log(res);
      commit('GET_CATEGORY2LIST',{res,category1Id})
  },
  getCategory3List:async ({commit,state},category2Id)=>{
    const res = await getCategory3ListApi(category2Id)
  //  console.log(res);
   commit('GET_CATEGORY3LIST',{res,category2Id})
}
  
};
export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
